package personnel.department.dao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;


public class HibernateUtils {
	
	private static SessionFactory sessionFactory;
	private static Session session;
	private static StandardServiceRegistry serviceRegistry;
	
	static {
		Configuration configuration = new Configuration().configure();
		//creates the session factory from hibernate.cfg.xml
		serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();      
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		session = sessionFactory.openSession();
		
	}
	
	public static Session getSession() {
		return session;
	}
	
	public static DAO getDAO() {
		return new DAOImpl();
	}
	
	public static void close() {
		StandardServiceRegistryBuilder.destroy(serviceRegistry);
	}
	
	
}
